<template>
  <div class="app">
    <hmHead></hmHead>
    <hmNavbar
      @click.native="$router.back()"
      title="新闻详情"
      left-text="返回"
    ></hmNavbar>

    <div class="news" v-for="item in NewsDetial" :key="item.id">
      <h1>{{ item.title }}</h1>
      <div class="dtai">
        <p>{{ item.category }}</p>
        <span>{{ new Date() | dateFormat }}</span>
      </div>
      <div v-html="item.content"></div>
    </div>
    <div class="rating"><Rating></Rating></div>
  </div>
</template>

<script>
import hmHead from "@/component/hm-head.vue";
import hmNavbar from "@/component/hm-navbar.vue";
import { NewsDetial } from "@/api/news.js";
import Rating from "@/component/hm-rating";
export default {
  components: {
    hmNavbar,
    hmHead,
    Rating,
  },
  data() {
    return {
      NewsDetial: [],
    };
  },
  mounted() {
    NewsDetial(this.$route.params.newid).then((res) => {
      // console.log(res);
      // this.NewsDetial = res.data.message;
      // console.log(this.NewsDetial);

      let result=res.data.message
      result.forEach(element => {
        element.value=1
      });
      // console.log(result);
      localStorage.setItem("NewsDetial",JSON.stringify(result));
      this.NewsDetial=result;
    });
  },
};
</script>

<style lang="less" scoped>
.app {
  padding-bottom: 80px;
}
.news {
  padding: 10px;
  font-weight: 400;
  text-indent: 2em;
}
h1 {
  text-indent: 0;
  font-size: 20px;
  font-weight: 700;
}
.dtai {
  display: flex;
  justify-content: space-between;
  padding: 10px;
  p {
    color: red;
  }
  span {
    color: #ccc;
  }
}
.rating {
  text-align: center;
}
</style>